// opt: 2
// std: gnu++11
// run: time $exec
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

int const maxn = 101;
int map[maxn][maxn];

bool vis[maxn];
int n;

struct edge { int v, cost; };

struct cmp
{
	bool operator()(edge a, edge b) { return a.cost > b.cost; }
};

int prim(int x)
{
	fill(vis, vis+n, false);
	priority_queue<edge, vector<edge>, cmp> pq;
	vis[x] = true;
	for (int i = 0; i < n; i++) {
		if (i == x) continue;
		edge tmp{i, map[x][i]};
		pq.push(tmp);
	}

	int min_tree = 0;
	for (int time = 0; time < n-1; time++) {
		edge now = pq.top(); pq.pop();
		for (; vis[now.v]; pq.pop()) now = pq.top();
		min_tree += now.cost;
		vis[now.v] = true;
		for (int i = 0; i < n; i++)
			if (!vis[i]) {
				edge tmp{i, map[now.v][i]};
				pq.push(tmp);
			}
	}
	return min_tree;
}

int main()
{
	while (cin >> n) {
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) cin >> map[i][j];
		cout << prim(0) << endl;
	}
}
